<?php

namespace addons\sum\controller\goods;

use addons\sum\controller\Common;
use addons\sum\service\goods\GoodsService;
use app\admin\model\sum\store\activity\Activity as StoreActivityModel;
use app\admin\model\sum\store\activity\SkuPrice as ActivitySkuPriceModel;
use app\admin\model\sum\store\Store as StoreModel;
use app\admin\model\sum\store\StoreGoods as StoreGoodsModel;

class ActivityGoods extends Common
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 商品列表
     * @return void
     */
    public function index(){
        $params = $this->request->param();
        $store_ids=$params['store_ids']??'';
        if(!$store_ids){
            $store_ids='5';//默认的店铺id-方便审核测试
//            $this->error('参数错误');
        }
        $store_ids_arr=explode(',',$store_ids);

        $sort = $params['sort'] ?? 'id';
        $order = $params['order'] ?? 'desc';

        //获取员工对应的或区域的内商户的进行中的活动
        $activity_ing_ids=StoreActivityModel::whereIn('store_id',$store_ids_arr)->whereNull('deletetime')->ing()->column('id');
        $recodes = ActivitySkuPriceModel::hasWhere('goods',function ($q){
            $q->where('Goods.status','up');
            return $q;
        })->with(['goods','activity'])
            ->whereIn('activity_id',$activity_ing_ids)
            ->where('SkuPrice.status', 'up')
            ->order($sort, $order)
            ->paginate();

        $recodes->each(function ($record){
            $record->store_id=$record->activity->store_id;
        });
        $this->success('获取成功', $recodes);



    }




}
